package com.ck.unis;

import java.util.*;

public class ContactDemo {

    public static void main(String[] args) {
        //超级SIM卡联系人
        List<Contact> simList = new ArrayList<>();
        //手机联系人
        List<Contact> phoneList = new ArrayList<>();

        //添加张三超卡数据
        addSimList(simList);
        System.out.println("张三的超卡数据:"+simList);

        //添加张三手机卡数据
        addPhoneList(phoneList);
        System.out.println("张三的手机数据:"+phoneList);

        List<Contact> list = moveData(simList,phoneList);
        System.out.println("移动后的手机卡数量:"+list.size()+"___数据:"+list);
    }

    /**
     * 将超卡数据移动到手机卡去
     * @param simList
     * @param phoneList
     * @return List<Contact> 移动后的数据
     */
    private static List<Contact> moveData(List<Contact> simList, List<Contact> phoneList){
        //手机号码数组拷贝一个新的地址
        List<Contact> list = new ArrayList<>();
        list.addAll(phoneList);
        Set<String> set = new HashSet<>();
        for(Contact tempData:phoneList){
            set.add(tempData.getName());
        }
        for(Contact simData:simList){
            boolean flag = false;
            for(Contact phoneData:phoneList){
                //判断两个联系人姓名是否相同, 是则判断,手机号码,不是则过
                if(simData.getName().equals(phoneData.getName())){
                    flag = judgePhoneList(simData.getPhone(),phoneData.getPhone());
                }
            }
            if(!flag){
                list.add(simData);
            }
            if(!set.contains(simData.getName())){
                list.add(simData);
            }
        }
        return list;
    }

    /**
     * 判断联系人手机号码是否完全相同
     * @param simList
     * @param phoneList
     * @return boolen 完全相同为true
     */
    private static boolean judgePhoneList(List<String> simList,List<String> phoneList){
        boolean flag = true;
        if(simList.size() == phoneList.size()){
            System.out.println("数据完全一致,不进行移动");
            System.out.println("simList:"+simList+"_phoneList:"+phoneList);
        }else{
            Collections.sort(simList);
            Collections.sort(phoneList);

            if(simList.equals(phoneList)){
                System.out.println("数据完全一致,不进行移动↓↓↓");
                System.out.println("simList:"+simList+"_phoneList:"+phoneList);
            }else{
                System.out.println("数据不一样,需要进行移动↓↓↓");
                System.out.println("simList:"+simList+"_phoneList:"+phoneList);
                flag= false;
            }
        }
        return flag;
    }

    /**
     * 给超级SIM卡添加联系人
     * @param simList
     */
    private static void addSimList(List<Contact> simList){
        //情况一: 有相同联系人, 手机号码不一样
        Contact contact = new Contact();
        contact.setName("张三");
        List<String> zsList = new ArrayList<>();
        zsList.add("130");
        zsList.add("131");
        contact.setPhone(zsList);
        simList.add(contact);

        //情况二: 有相同联系人, 手机号码相同
        contact = new Contact();
        contact.setName("王五");
        zsList = new ArrayList<>();
        zsList.add("133");
        zsList.add("134");
        contact.setPhone(zsList);
        simList.add(contact);

        //情况三: 有相同联系人, 超卡联系人有手机号码, 手机卡联系人手机号码为空
        contact = new Contact();
        contact.setName("李四");
        zsList = new ArrayList<>();
        zsList.add("133");
        contact.setPhone(zsList);
        simList.add(contact);

        //情况四: 无相同联系人, 仅超卡有联系人
        contact = new Contact();
        contact.setName("陈一");
        zsList = new ArrayList<>();
        zsList.add("133");
        contact.setPhone(zsList);
        simList.add(contact);

        //情况六: 有相同联系人, 超卡联系人有手机号码, 手机卡联系人手机号码为空
        contact = new Contact();
        contact.setName("李四");
        zsList = new ArrayList<>();
        zsList.add("134");
        contact.setPhone(zsList);
        simList.add(contact);
    }


    /**
     * 给手机添加联系人
     * @param phoneList
     */
    private static void addPhoneList(List<Contact> phoneList){
        Contact contact = new Contact();
        contact.setName("张三");
        List<String> zsList = new ArrayList<>();
        zsList.add("131");
        contact.setPhone(zsList);
        phoneList.add(contact);

        contact = new Contact();
        contact.setName("张三");
        zsList = new ArrayList<>();
        zsList.add("132");
        contact.setPhone(zsList);
        phoneList.add(contact);

        contact = new Contact();
        contact.setName("王五");
        zsList = new ArrayList<>();
        zsList.add("134");
        zsList.add("133");
        contact.setPhone(zsList);
        phoneList.add(contact);

        contact = new Contact();
        contact.setName("李四");
        zsList = new ArrayList<>();
        contact.setPhone(zsList);
        phoneList.add(contact);

        //情况五
        contact = new Contact();
        contact.setName("刘七");
        zsList = new ArrayList<>();
        contact.setPhone(zsList);
        phoneList.add(contact);
    }

    static class Contact{
        private String name;
        private List<String> phone;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public List<String> getPhone() {
            return phone;
        }

        public void setPhone(List<String> phone) {
            this.phone = phone;
        }

        @Override
        public String toString() {
            return "Contact{" +
                    "name='" + name + '\'' +
                    ", phone=" + phone +
                    '}';
        }
    }
}
